using System;
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Gebra.Test
{
    [TestClass]
    public class FunctionTest
    {
        [TestMethod]
        public void ConstructAddFunctionWithOneVariable()
        {
            var x = new Variable();
            var operand = new Add((Number) 3, x);
            var function = new Function(operand, x);

            var result = function.Evaluate((Number) 4) as Number;

            Assert.IsNotNull(result);
            Assert.AreEqual(7, (double) result);
        }

        [TestMethod]
        public void ConstructAddFunctionWithTwoVariables()
        {
            var z = new Variable();
            var c = new Variable();
            var function = new Function(z.Raise(2).Add(c), z, c); // z^2 + c

            var result = function.Evaluate((Number)new Complex(1.5, 1.5), (Number)5) as Number;

            Assert.IsNotNull(result);
            Assert.IsTrue(new Complex(5, 4.5).Distance((Complex)result) < 0.000001);
        }
    }
}